<template>
    <div class="apply-list" v-loading="loading">
        <div class="input-box">
            <span class="input-title">用户ID</span>
            <el-input
                placeholder="用户ID"
                @keyup.enter.native="getList(1)"
                style="width:120px;"
                clearable
                v-model.trim="paramsList.userId">
            </el-input>
            <span class="input-title" style="margin-left: 20px;">大号区服</span>
            <el-select @change="getList(1)" clearable style="width:120px;" v-model="paramsList.serverType">
                <el-option label="全部" :value="null"></el-option>
                <el-option label="微信" :value="1"></el-option>
                <el-option label="QQ" :value="2"></el-option>
            </el-select>
            <span class="input-title" style="margin-left: 20px;">处理状态</span>
            <el-select @change="getList(1)" style="width:120px;" v-model="paramsList.listType">
                <el-option label="未处理" :value="0"></el-option>
                <el-option label="已处理" :value="1"></el-option>
            </el-select>
            <el-button type="primary" class="btn" style="margin-left:20px" @click="getList(1)">查询</el-button>
        </div>
        <div class="table-box">
            <el-table :data="tableData" ref="table" @sort-change="sortChange" border style="width: 100%">
                <el-table-column width="220" prop="userId" label="用户id">
                    <template slot-scope="scope">
                        <div class="table-flex">
                            <img class="user-avatar" :src="scope.row.avatar" alt="">
                            <div class="user-info">
                                <p class="table-btn" @click="goUserDetail(scope.row.userId )">趣ID：{{ scope.row.userId }}</p>
                                <p>昵称：{{ scope.row.nickname }}</p>
                            </div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column width="80" prop="gex" label="性别">
                    <template slot-scope="scope">
                        <div v-if="scope.row.gex == 0">男</div>
                        <div v-if="scope.row.gex == 1">女</div>
                    </template>
                </el-table-column>
                <el-table-column width="100" prop="age" label="年龄">
                    <template slot-scope="scope">
                        <div v-if="scope.row.age == 0">1-14岁以下</div>
                        <div v-if="scope.row.age == 1">14-18岁</div>
                        <div v-if="scope.row.age == 2">19-25岁</div>
                        <div v-if="scope.row.age == 3">26-30岁</div>
                        <div v-if="scope.row.age == 4">31-40岁</div>
                        <div v-if="scope.row.age == 5">40岁以上</div>
                    </template>
                </el-table-column>
                <el-table-column width="140" prop="maxHistoryJobLevel" label="历史最高段位" sortable="custom"></el-table-column>
                <el-table-column width="80" prop="serverType" label="区服">
                    <template slot-scope="scope">
                        <div v-if="scope.row.serverType == 1">微信</div>
                        <div v-if="scope.row.serverType == 2">QQ</div>
                    </template>
                </el-table-column>
                <el-table-column width="120" prop="stampCount" label="印记数量" sortable="custom">
                    <!-- <template slot-scope="scope">
                        <div v-if="scope.row.gstampCountex == 0">0</div>
                        <div v-if="scope.row.stampCount == 1">1</div>
                        <div v-if="scope.row.stampCount == 2">2-5</div>
                        <div v-if="scope.row.stampCount == 3">6-10</div>
                        <div v-if="scope.row.stampCount == 4">10以上</div>
                    </template> -->
                </el-table-column>
                <el-table-column width="120" prop="maxHistoryScore" label="巅峰赛积分" sortable="custom"></el-table-column>
                <el-table-column width="120" prop="smallAccountCount" label="小号数量" sortable="custom"></el-table-column>
                <el-table-column width="100" prop="smallAccountType" label="小号区服">
                    <template slot-scope="scope">
                        <div v-if="scope.row.smallAccountType == 0">微信</div>
                        <div v-if="scope.row.smallAccountType == 1">QQ</div>
                        <div v-if="scope.row.smallAccountType == 3">都有</div>
                        <div v-if="scope.row.smallAccountType == 4">没有小号</div>
                    </template>
                </el-table-column>
                <el-table-column width="120" prop="smallAccountJobLevel" label="小号段位">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.smallAccountJobLevel" :key="index">
                            <div v-if="item == 0">没有小号</div>
                            <div v-if="item == 1">青铜</div>
                            <div v-if="item == 2">白银</div>
                            <div v-if="item == 3">黄金</div>
                            <div v-if="item == 4">铂金</div>
                            <div v-if="item == 5">钻石</div>
                            <div v-if="item == 6">星耀</div>
                            <div v-if="item == 7">最强王者低星</div>
                            <div v-if="item == 8">最强王者高星</div>
                            <div v-if="item == 9">荣耀王者低星</div>
                            <div v-if="item == 10">荣耀王者高星</div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column width="120" prop="playTime" label="可接单时长">
                    <template slot-scope="scope">
                        <div v-if="scope.row.playTime == 0">20分钟</div>
                        <div v-if="scope.row.playTime == 1">1-3小时</div>
                        <div v-if="scope.row.playTime == 2">3-5小时</div>
                        <div v-if="scope.row.playTime == 3">5小时以上</div>
                    </template>
                </el-table-column>
                <el-table-column width="140" prop="openVoice" label="开语音状态">
                    <template slot-scope="scope">
                        <div v-if="scope.row.openVoice == 0">可以开</div>
                        <div v-if="scope.row.openVoice == 1">偶尔开</div>
                        <div v-if="scope.row.openVoice == 3">大部分时间不方便开</div>
                        <div v-if="scope.row.openVoice == 4">从来不开</div>
                    </template>
                </el-table-column>
                <el-table-column min-width="100" label="营地id" prop="ydid"></el-table-column>
                <el-table-column min-width="150" label="大号总对局场次" prop="maxPlayGameTime" sortable="custom"></el-table-column>
                <el-table-column min-width="120" label="mvp场次" prop="mvpPlayGameTime" sortable="custom"></el-table-column>
                <el-table-column min-width="170" label="战力超2000的英雄" prop="upTwoHeroCount" sortable="custom"></el-table-column>
                <el-table-column min-width="130" label="满级英雄个数" prop="oftenUseHeroCount" sortable="custom"></el-table-column>
                <el-table-column width="150" prop="titleList" label="荣誉信息">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.titleList" :key="index">
                            <div>{{ item }}</div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column width="120" prop="pictureList" label="荣誉图片信息">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.pictureList" :key="index">
                            <el-image v-if="!index" :src="item" :preview-src-list="scope.row.pictureList" style="width: 100px;"></el-image>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column fixed="right" label="操作">
                    <template slot-scope="scope">
                        <div>
                            <el-button v-if="!scope.row.status" @click="operateStatus(scope.row, 2)" type="text" size="small" style="margin-left: 10px;">通过</el-button>
                            <el-button v-if="!scope.row.status" @click="operateStatus(scope.row, 1)" type="text" size="small" style="color:red;">驳回</el-button>
                            <p v-if="scope.row.status === 1">已驳回</p>
                            <p v-if="scope.row.status === 2" style="color:#67C23A;">已通过</p>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <div class="tools">
            <el-pagination
                @size-change="sizeChange"
                @current-change="pageChange"
                :current-page="pageNum"
                :page-sizes="_pageSizes"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div>

        <el-dialog class="dialog-box" title="设置可服务段位" :visible.sync="dialogVisible" width="260px">
            <div>
                <el-select style="width:200px;" v-model="maxJobLevel">
                    <el-option label="铂金及以下" :value="13"></el-option>
                    <el-option label="星耀及以下" :value="15"></el-option>
                    <el-option label="王者25星及以下" :value="16"></el-option>
                    <el-option label="王者50星及以下" :value="17"></el-option>
                </el-select>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="setJobLevel">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: 'applyList',
    props: {
        tabIndex: ''
    },
    data () {
        return {
            imgSrc: '',
            maxJobLevel: '',
            paramsList: {
                listType: 0
            },
            tableData: [],
            skinList: [],
            pageNum: 1,
            pageSize: this._pageSize,
            total: 0,
            dialogVisible: false,
            loading: false
        }
    },
    watch: {
        tabIndex: function (val) {
            if (val === '2') {
                this.getList(1)
            }
        }
    },
    methods: {
        // 获取列表
        async getList (pageNum) {
            if (this.loading) return
            this.pageNum = pageNum
            this.loading = true
            let params = {
                pageNum,
                pageSize: this.pageSize,
                orderType: this.sort,
                orderColumn: this.orderColumn
            }
            params = Object.assign(params, this.paramsList)
            let res = await this.$http.post('/team/kingApplies', params)
            if (res.code === '0') {
                this.tableData = res.data && res.data.list
                this.imgSrc = this.tableData && this.tableData.pictureList && this.tableData.pictureList[0]
                this.total = res.data.totalRow
            } else {
                this.$message({
                    type: 'error',
                    message: res.desc
                })
            }
            this.loading = false
        },

        // 页码切换
        sizeChange (val) {
            this.pageNum = 1
            this.pageSize = val
            this.getList(1)
        },

        // 页容切换
        pageChange (val) {
            this.pageNum = val
            this.getList(this.pageNum)
        },

        setJobLevel () {
            if (this.maxJobLevel) {
                let params = {
                    ids: [this.currentItem.userId],
                    operateType: this.operateType,
                    maxJobLevel: this.maxJobLevel
                }
                this.$http.post('/team/operateKingApplies', params).then(res => {
                    if (res.code === '0') {
                        this.currentItem.status = this.operateType
                        this.maxJobLevel = null
                        this.$message({
                            type: 'success',
                            message: '操作成功'
                        })
                    } else {
                        this.$message({
                            type: 'error',
                            message: res.desc
                        })
                    }
                })
                this.dialogVisible = false
            } else {
                this.$message({
                    type: 'error',
                    message: '请选择服务段位'
                })
            }
        },
        operateStatus (item, operateType) {
            let msg = ''
            if (operateType === 1) {
                msg = `确认驳回${item.userId}的申请吗？`
                this.$confirm(msg, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let params = {
                        ids: [item.userId],
                        operateType
                    }
                    this.$http.post('/team/operateKingApplies', params).then(res => {
                        if (res.code === '0') {
                            item.status = operateType
                            this.$message({
                                type: 'success',
                                message: '操作成功'
                            })
                        } else {
                            this.$message({
                                type: 'error',
                                message: '系统异常，请稍后再试'
                            })
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '取消操作'
                    })
                })
            } else {
                this.dialogVisible = true
                this.currentItem = item
                this.operateType = operateType
                // msg = `确认通过${item.userId}的申请吗？`
            }
        },
        sortChange ({ column, prop, order }) {
            this.sort = order || ''
            // 如果没有 sort prop 置为空
            if (!this.sort) {
                this.type = null
            } else {
                if (this.sort === 'ascending') {
                    this.sort = 'asc'
                } else {
                    this.sort = 'desc'
                }
                this.orderColumn = prop
            }
            this.getList(1)
        },
        goUserDetail (id) {
            const { href } = this.$router.resolve({
                path: '/dataReport/userInfo',
                query: {
                    id
                }
            })
            window.open(href, '_blank')
        }
    }
}
</script>

<style lang="scss" scoped>
    .apply-list {
        .table-box {
            margin: 20px 0;
            .table-btn {
                cursor: pointer;
                color: #409EFF;
                font-size: 13px;
                font-weight: 500;
                &:hover {
                    text-decoration: underline;
                }
            }
            .table-flex {
                display: flex;
                align-items: center;
                .user-avatar {
                    display: inline-block;
                    min-width: 60px;
                    height: 60px;
                    margin-right: 5px;
                    border-radius: 50%;
                }
                .user-info {
                    display: flex;
                    flex-direction: column;
                    justify-content: center;
                }
            }
        }
        .input-box {
            margin-top: 10px;
            font-size: 13px;
            font-weight: 500;
            .input-title {
                margin: 0 10px 0 0px;
            }
            .btn {
                margin-top: 10px;
                margin-left: 10px;
            }
        }
        .picture {
            width: 300px;
            height: 300px;
        }

        .tools {
            padding-right: 20px;
            display: flex;
            justify-content: flex-end;
        }
    }
</style>
